package com.yanqu.road.server.cmd.activity.feast.cross;

import com.yanqu.road.entity.activity.args.ValueFourParamArgs;
import com.yanqu.road.entity.enums.eGamePlayerEventType;
import com.yanqu.road.message.YanQuMessage;
import com.yanqu.road.pb.activity.ShanHeFeastProto;
import com.yanqu.road.server.command.Cmd;
import com.yanqu.road.server.command.Command;
import com.yanqu.road.server.gameplayer.GamePlayer;
import com.yanqu.road.server.gameplayer.module.activity.ActivityModule;
import com.yanqu.road.server.manger.player.GamePlayerMgr;
import com.yanqu.road.server.protocol.GameProtocol;
import io.netty.channel.ChannelHandlerContext;

import java.math.BigInteger;

@Cmd(code = GameProtocol.S_SHAN_HE_FEAST_NOTIFY_CONDITION_FROM_CROSS, desc = "同步condition更新  跨服返回")
public class FeastNotifyConditionFromCrossCmd implements Command {

    @Override
    public void execute(ChannelHandlerContext ctx, YanQuMessage packet) throws Exception {
        ShanHeFeastProto.CrossFeastNotifyConditionRespMsg respMsg = ShanHeFeastProto.CrossFeastNotifyConditionRespMsg.parseFrom(packet.getBytes());
        GamePlayer onlinePlayer = GamePlayerMgr.getOnlinePlayer(respMsg.getUserId());
        if (onlinePlayer != null) {
            onlinePlayer.getModule(ActivityModule.class).startChanges();
            if(respMsg.getConditionType() == eGamePlayerEventType.FeastPersonalScore.getValue()){
                onlinePlayer.notifyListener(respMsg.getConditionType(), new ValueFourParamArgs(BigInteger.valueOf(respMsg.getValue()), respMsg.getRound()));
            }else {
                onlinePlayer.notifyListener(respMsg.getConditionType(), respMsg.getValue());
            }
            onlinePlayer.getModule(ActivityModule.class).finishChanges();
        }
    }

}
